package timing.ukulele.project.service;

import timing.ukulele.common.ResponseResult;
import timing.ukulele.persistent.service.BaseService;
import timing.ukulele.project.mapper.DictionaryContentMapper;
import timing.ukulele.project.persistent.DictionaryContent;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictionaryContentService extends BaseService<DictionaryContentMapper, DictionaryContent> {


    public ResponseResult<List<DictionaryContent>> findByDictionaryId(Long dictionaryId) {
        return ResponseResult.success(this.lambdaQuery().eq(DictionaryContent::getDictionaryId, dictionaryId).list());
    }

    public List<DictionaryContent> saveContent(List<DictionaryContent> content, String username) {
        Map<String, Object> map = new HashMap<>();
        map.put("dictionary_id", content.get(0).getDictionaryId());
        getBaseMapper().deleteByMap(map);
        for (DictionaryContent dictionaryContent : content) {
            dictionaryContent.setCreateBy(username);
            dictionaryContent.setUpdateBy(username);
            getBaseMapper().insert(dictionaryContent);
        }
        return content;
    }

}
